package com.itheima.test;

import java.util.Arrays;

public class QuickSort {
    public static void main(String[] args) {
        int[] arr = {4, 1, 2, 5, 543, 2, 34, 6, 34, 10};

        quickSort(arr,0,arr.length-1);

        String s = Arrays.toString(arr);
        System.out.println(s);
    }

    private static void quickSort(int[] arr, int left, int right) {
        if (left > right){
            return;
        }
        int left0 = left;
        int right0 = right;

        int baseNumber = arr[left0];

        while (left != right) {

            while (arr[right] >= baseNumber && left < right) {
                right--;
            }
            while (arr[left] <= baseNumber && left < right) {
                left++;
            }

            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
        }

        int temp = arr[left];
        arr[left] = arr[left0];
        arr[left0] = temp;

        quickSort(arr, left0,left-1);
        quickSort(arr, left+1, right0);
    }
}
